<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper search-box-cuesList" style="margin-bottom:10px">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="28">
                    <a-col :xl="5" :lg="8" :md="7" :sm="26">
                        <a-form-item label="标题">
                            <a-input v-model="queryParam.contentTitle" placeholder="请输入标题"/>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="4" :lg="7" :md="6" :sm="6">
            <span style="float: left;overflow: hidden; margin-left:-40px" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" title="搜索" shape="circle"></a-button>
            </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- table区域-begin -->
        <div>
            <a-table ref="table" size="middle" rowKey="id" :columns="columns"
                     :dataSource="dataSource"
                     :pagination="ipagination"
                     :loading="loading"
                     :rowSelection="isSelect?{type:'radio',onChange:onSelectChange}:null"
                     @change="handleTableChange">
                <template slot="操作" slot-scope="text,record">
                    <a @click="showPhone(text,record)">预览</a>
<!--                    <a-divider type="vertical" v-if="record.syncStatus != 1"/>-->
<!--                    <a @click="pushToPaper(text,record)" v-if="record.syncStatus != 1">发布到纸媒</a>-->
                </template>
            </a-table>
        </div>
        <preview ref="preview"></preview>
    </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import Preview from '@/components/xinke/preview/Preview'
  import { getAction } from '@/api/manage'

  export default {
    name: 'ArticleTemplateList',
    mixins: [JeecgListMixin],
    components: { Preview },
    props: {
      'isSelect': {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        // 表头
        columns: [
          {
            title: '标题名称',
            align: 'center',
            dataIndex: 'contentTitle'
          },
          {
            title: '副标题',
            align: 'center',
            dataIndex: 'contentSubTitle'
          },
          // {
          //   title: '作者',
          //   align: 'center',
          //   dataIndex: 'authorName',
          // },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: '操作',
            width: '150px',
            scopedSlots: { customRender: '操作' }
          }
        ],
        url: {
          list: 'content/contentTemplate/templateList'
        }
      }
    },
    methods: {
      showPhone(text, record) {
        record.richContent = record.content
        this.$refs.preview.show(record)
      },
      pushToPaper(text, record) {
        getAction('/paper/paperLanding/sync', { id: record.id }).then(res => {
          if (res.success) {
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        if(selectedRows && selectedRows.length){
          const {id,contentTitle} = selectedRows[0];
          this.$emit('selectChange',{
            id,contentTitle,
          });
        }else{
          this.$emit('selectChange',{});
        }
      }
    }
  }
</script>
<style scoped lang="less">;
</style>
